package com.codefactory.generator.method;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

import java.io.IOException;
import java.io.Writer;
import java.util.Map;

public class UpperCaseMethod2 implements TemplateDirectiveModel {
    @Override
    public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
        // 获取输入字符串
        String inputString = params.get("string").toString();

        // 将字符串转换为大写
        String upperCaseString = inputString.toUpperCase();

        // 将结果写入输出流
        try (Writer out = env.getOut()) {
            out.write(upperCaseString);
        } catch (IOException e) {
            //throw new TemplateException(e);
        }
    }
}